package cc.linker.steplink.crm.merchant.controller;

import cc.linker.steplink.crm.commons.model.PcUserInfo;
import cc.linker.steplink.crm.merchanth5.commons.UserInfoUtil;
import cc.linker.steplink.crm.merchant.service.GoodsDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods/data")
public class GoodsDataController {

    @Autowired
    private GoodsDataService goodsDataService;
    @Autowired
    private UserInfoUtil userInfoUtil;

    @PostMapping("/listGoodsData")
    public Object listGoodsData(@RequestBody Map<String, Object> param, HttpServletRequest request) {
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        param.put("orgId", userinfo.getOrgId());
        return goodsDataService.listGoodsData(param);
    }

    @GetMapping("/getGoodsData")
    public Map<String, Object> getGoodsData(String goodsId) {
        return goodsDataService.getGoodsDataByGoodsId(goodsId);
    }

    /**
     * 商品区间数据
     *
     * @param goodsId   商品id
     * @param type      1-浏览量\2-加购人数\3-支付人数\4-昨日成交单数\5-加购件数\6-访客数\7-支付商品件数
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @GetMapping("/getGoodsIntervalData")
    public List<Map<String, Object>> getGoodsIntervalData(String goodsId, Integer type, String startTime, String endTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("goodsId", goodsId);
        map.put("type", type);
        map.put("startTime", startTime);
        map.put("endTime", endTime);

        return goodsDataService.getGoodsDataByGoodsIdAndType(map);
    }


    /**
     * 报名活动数据列表
     * @param param
     * @return
     */
    @PostMapping("/listEnrollData")
    public Object listEnrollData(@RequestBody Map<String, Object> param, HttpServletRequest request) {
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        param.put("orgId", userinfo.getOrgId());
        return goodsDataService.listEnrollData(param);
    }

    /**
     * 报名活动数据看板
     * @return
     */
    @GetMapping("/getEnrollData")
    public Map<String, Object> getEnrollData(String enrollId) {
        return goodsDataService.getEnrollDataByEnrollId(enrollId);
    }

    /**
     * 商品区间数据
     *
     * @param enrollId
     * @param type      1-浏览量\3-报名人数\6-访客数\9-销售金额
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @GetMapping("/getEnrollIntervalData")
    public List<Map<String, Object>> getEnrollIntervalData(String enrollId, Integer type, String startTime, String endTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("enrollId", enrollId);
        map.put("type", type);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        return goodsDataService.getEnrollDataByEnrollIdAndType(map);
    }
}
